package cn.gok;


import java.io.*;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Calendar;

public class 作业4 {
    public static void main(String[] args) throws IOException {
        /*
        大数运算
        */
        getBigResult();
        /*
        生日
        */
        birday();
        /*
        Java文件s
         */
        File file = new File("F:\\idea\\rrrrr\\day4\\src");
        showJava(file);
        /*

         */
        copy();
        /*
        utf-8 -> GBK
        */
        change();
    }

    private static void change() throws IOException {
        InputStreamReader isr = new InputStreamReader(new FileInputStream("F:\\idea\\rrrrr\\day4\\src\\cn\\gok\\HelloWorld.txt"), "utf-8");
        char bs[] = new char[10];
        int len = 0;
        String string = new String();
        while (((len = isr.read(bs)) != -1)) {
            string = new String(bs, 0, len);
        }
        OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream("F:\\idea\\rrrrr\\day4\\src\\cn\\gok\\c.txt"), "GBK");
        osw.write(string);
        osw.close();
        isr.close();
        System.out.println("转换成功");
    }

    private static void copy() throws IOException {
        File file = new File("F:\\idea\\rrrrr\\day4\\src\\cn\\gok\\HelloWorld.txt");
        file.mkdir();
        if (file.isFile()) {
            System.out.println("是文件");
        } else if (file.isDirectory()) {
            System.out.println("是目录");
        }
        File file2 = new File("F:\\idea\\rrrrr\\day4\\src\\cn\\gok\\IOTest");
        file2.mkdir();
        Reader re = new FileReader("F:\\idea\\rrrrr\\day4\\src\\cn\\gok\\HelloWorld.txt");
        Writer wr = new FileWriter("F:\\idea\\rrrrr\\day4\\src\\cn\\gok\\IOTest\\a.txt");
        char c[] = new char[100];
        int len = 0;
        while ((len = re.read(c)) != -1) {
            String string = new String(c, 0, len);
            wr.write(string);
        }
        System.out.println("复制成功");
        wr.close();
        re.close();
    }

    private static void birday() {
        Calendar d1 = Calendar.getInstance();
        d1.set(2001, 1, 6);
        d1.add(Calendar.DAY_OF_MONTH, -5);
        int n = d1.get(Calendar.DAY_OF_YEAR);
        System.out.println(n);
    }


    private static void showJava(File file) {
        File file1[] = file.listFiles();
        for (File i : file1) {
            if (i.isFile()) {
                if (i.getName().endsWith(".java"))
                    System.out.println(i.getAbsolutePath());
            } else if (i.isDirectory()) {
                showJava(i);
            }
        }
    }

    public static void getBigResult() {
        BigDecimal b1 = BigDecimal.valueOf(4444444.4444);
        BigDecimal b2 = BigDecimal.valueOf(3.333333);
        BigDecimal result = b1.divide(b2, 2, RoundingMode.HALF_UP);
        System.out.println(result);
    }
}
